var url = "ws://swoole.kinggui.com:8812";
var ws = new WebSocket(url);
//
ws.onopen = function (evt) {
    console.log('connected chat success!');
}
ws.onmessage = function (evt) {
    console.log("chat-server-return:" + evt.data);
    push(evt.data);
}
ws.onclose = function (evt) {
    console.log('chat disconnnected!');
}
ws.onerror = function (evt) {
    console.log('chat occur a wrong');
}

function push(data){
    var data = JSON.parse(data);
    var html = '<div class="comment">';
    html += '<span>' + data.user + '</span>' + ":";
    html += '<span>' + data.content + '</span>';
    html += '</div>';

    $('#comments').append(html);
}